<?php
	global $db;
	$data = $_POST;
	$query = "SELECT pictures FROM tour where id = ".$data['tour_id'];
	$r = $db->query($query);
	$res = $db->fetch($r);
	$pictures = json_decode($res['pictures'], true);
	$to_delete = array($data['pic_name']);
	$pic_list = $pictures['picture_list'];
	$pic_list = array_diff($pic_list, $to_delete);
	$pictures['picture_list'] = $pic_list;
	$pictures = json_encode($pictures);
	$query = "UPDATE tour SET pictures = '".$pictures."' WHERE id = ".$data['tour_id'];
	$db->query($query);
	// delete file on server
	$up_dir	= "../images/";
	unlink($up_dir.$data['pic_name']);
	echo mysql_error();
?>